package game.leon.engine.net.example;

import game.leon.engine.net.example.client.Client;
import game.leon.engine.net.codec.GateRawMessage;
import game.leon.engine.net.example.server.Server;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.StopWatch;

import java.io.IOException;

/**
 * User: bianpeng
 * Date: 11-12-23
 */
public class LeonMain {

    public static void main(String[] args) {
        Logger logger = Logger.getLogger(LeonMain.class);
        ApplicationContext context = new ClassPathXmlApplicationContext(
                new String[]{"application-context.xml"});
        StopWatch watch = new StopWatch();
        Server server = context.getBean(Server.class);
        try {
            watch.start();
            server.start();
            watch.stop();
            logger.info(String.format("server start in %d ms", watch.getLastTaskTimeMillis()));
        } catch (IOException e) {
            logger.error("server start failed", e);
        }

        Client client = context.getBean(Client.class);
        try {
            watch.start();
            client.start();
            watch.stop();
            logger.info(String.format("client start in %d ms", watch.getLastTaskTimeMillis()));
        } catch (IOException e) {
            logger.error("client start failed", e);
        }
        // ok, all done
        client.send(new GateRawMessage(0x1234, 0x5678, new byte[]{0x9, 0x10}));
        /*
        暂时不用clojure的内容
        watch.start();
        game.leon.hello.greet();
        watch.stop();
        logger.info(String.format("clj start in %d ms", watch.getLastTaskTimeMillis()));
        */
    }
}
